
$(document).ready(function () {
    if ($('#MSOLayout_InDesignMode').val() == 1) {

}
else
{
    $(".WebPartTabsDiv").hide();
    $(".WebPartTabsDiv").html(GetTabHtml());
    $(".WebPartTabsDiv").show();
}
});

/* Swtich tabs Logic */

function switchTab(target) {


    //Hide selected tab container
    $('#tab-box div.TSTabContentsSelected').removeClass('TSTabContentsNormal');
    $('#tab-box div.TSTabContentsSelected').addClass('TSTabContentsNormal');
    $('#tab-box div.TSTabContentsSelected').removeClass('TSTabContentsSelected');
    // Unselect the current tab strip
    $('#tab-strip li.TSTabSelBlue').addClass('TSTabBlue');
    $('#tab-strip li.TSTabSelBlue').removeClass('TSTabSelBlue');
    // Select current tab strip
    $(target).addClass('TSTabContentsSelected');
    $(target).removeClass('TSTabContentsNormal');
    // Show selected tab container
    $(target.replace('content_', '')).addClass('TSTabSelBlue');
    $(target.replace('content_', '')).removeClass('TSTabBlue');
}



function GetTabHtml()
{
var tabStrip="<div id=\"tab-box\" class=\"box\"><ul id=\"tab-strip\" class=\"tabnav tabnavBlue\">";
tabStrip = tabStrip + GetTabs();
tabStrip = tabStrip + "</ul>";
tabStrip = tabStrip + GetTabContent();
tabStrip = tabStrip + "</div>";
return tabStrip;
}

function GetTabs()
{
var tabs = "";
var tabTitle = "";
var tabId = "";
$(".my-web-part-tabs > table > tbody > tr .ms-WPTitle").each(function(index)
{
    tabTitle = $(this).text();
    tabId = tabTitle + "Tab";
    if(index == 0)
    {
	       tabs = tabs + "<li id=\"" + tabId + "\" class=\"TSTabSelBlue\"><span style=\"height: 30px; text-decoration: none\" onmouseover=\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\" onclick=\"switchTab('#content_" + tabId + "')\">" + tabTitle + "</span></li>";

	
    }
    else
    {
	tabs = tabs + "<li id=\"" + tabId + "\" class=\"TSTabBlue\"><span style=\"height: 30px; text-decoration: none\" onmouseover=	\"this.style.textDecoration='underline'\" onmouseout=\"this.style.textDecoration='none'\" onclick=\"switchTab('#content_" + tabId + "')\">" + 			tabTitle + "</span></li>";
} 
    
});
return tabs;
}

function GetTabContent()
{
var tabContent = "";
$(".my-web-part-tabs > table > tbody > tr > td").each(function(index)
{
var divId = "content_" + $(this).find(".ms-WPTitle").text() + "Tab";

if(index == 0)
{
	tabContent = tabContent + "<div id=\"" + divId +"\" class=\"TSTabContentsSelected\"><div class=\"tabContent\">";	
}
else
{
	tabContent = tabContent + "<div id=\"" + divId +"\" class=\"TSTabContentsNormal\"><div class=\"tabContent\">";	
}

tabContent = tabContent + $(this).html() + "</div></div>";
});
return tabContent;
}


